package com.yingpai.fitness.dvp_2_0.main.activity.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.yingpai.fitness.R;
import com.yingpai.fitness.dvp_2_0.common.activity.CommonActivity;
import com.yingpai.fitness.dvp_2_0.common.adapter.BaseAdapterHelper;
import com.yingpai.fitness.dvp_2_0.common.adapter.QuickAdapter;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.callback.Callback;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.request.RequestType;
import com.yingpai.fitness.dvp_2_0.common.util.constant.Contacts;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Url;
import com.yingpai.fitness.entity.QuestionDetailBean;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ASUS on 2018/9/29.
 */

public class QuestionDetailActivity extends CommonActivity {

    @BindView(R.id.listview)
    ListView listview;
    private String id;
    private QuickAdapter<QuestionDetailBean> quickAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusFlag(Contacts.NORMAL_STATUS);
        setContentView(R.layout.help_web_view_activity);
    }

    @Override
    protected void initView() {
        setTitle("常见问题");

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            id = bundle.getString("id");
        }

        quickAdapter = new QuickAdapter<QuestionDetailBean>(this, R.layout.item_question_detail) {
            @Override
            protected void convert(BaseAdapterHelper helper, QuestionDetailBean item) {
                helper.setText(R.id.title, item.getQuestion());
                helper.setText(R.id.content, item.getAnswer());
            }
        };

        listview.setAdapter(quickAdapter);
    }

    @Override
    protected void initData() {
        showDialog(this, null);
        HttpParams params = new HttpParams();
        params.put("catalog", id);
        finalOkGo.request(RequestType.POSTLIST, Contacts.HOST_SERVER + Url.GET_QUESTION_DETAIL, params, Url.GET_QUESTION_DETAIL, new Callback<QuestionDetailBean>() {
            @Override
            public void onSuccess(QuestionDetailBean o) {

            }

            @Override
            public void onListSuccess(List<QuestionDetailBean> t) {
                super.onListSuccess(t);
                empty.setVisibility(View.GONE);
                dismissDialog();
                quickAdapter.clear();
                quickAdapter.addAll(t);
                quickAdapter.notifyDataSetChanged();
            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                empty.setVisibility(View.VISIBLE);
                dismissDialog();
            }
        });
    }

    @Override
    @OnClick({})
    public void onViewClicked(View view) {
        super.onViewClicked(view);
        switch (view.getId()) {

        }
    }
}
